/**
 * 
 */
package com.hurr.assembly;

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Collection;

import com.hurr.assembler.Assembler;
import com.hurr.bo.Expense;
import com.hurr.dto.ExpenseDto;

/**
 * @author Fernando Perelli
 *
 */
public class ExpenseAssembly {
	
	
	public ExpenseDto toDto(Expense expense) throws ClassNotFoundException, NoSuchMethodException, SecurityException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
		ExpenseDto expenseDto = new ExpenseDto();
		expenseDto.setId(expense.getId());
		expenseDto.setDate(expense.getDate());
		expenseDto.setDescription(expense.getDescription());
		expenseDto.setType(expense.getType());
		expenseDto.setValue(expense.getValue());
		return expenseDto;
	}
	
	public Expense toModel(ExpenseDto expenseDto) throws InstantiationException, IllegalAccessException, ClassNotFoundException, NoSuchMethodException, SecurityException, IllegalArgumentException, InvocationTargetException{
		Expense expense = new Expense();
		expense.setId(expenseDto.getId());
		expense.setDate(expenseDto.getDate());
		expense.setDescription(expenseDto.getDescription());
		expense.setType(expenseDto.getType());
		expense.setValue(expenseDto.getValue());
		return expense;
	}

	public Collection<ExpenseDto> toDtos(Collection<Expense> expenses) throws ClassNotFoundException, NoSuchMethodException, SecurityException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException{
		Collection<ExpenseDto> expenseDtos = new ArrayList<ExpenseDto>();
		for (Expense expense : expenses) {
			ExpenseDto expenseDto = (ExpenseDto) Assembler.toDto(expense);
			expenseDtos.add(expenseDto);
		}
		return expenseDtos;
	}
	
	public Collection<Expense> toModels(Collection<ExpenseDto> expenseDtos) throws ClassNotFoundException, NoSuchMethodException, SecurityException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException{
		Collection<Expense> expenses = new ArrayList<Expense>();
		
		for (ExpenseDto expenseDto : expenseDtos) {
			Expense expense= (Expense) Assembler.toModel(expenseDto);
			expenses.add(expense);
		}
		return expenses;
		
	} 


}
